package com.alan.base.config;

import android.app.Activity;
import android.graphics.Color;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

/**
 * 提供了配置顶部状态栏和底部导航栏的方法的基类
 * 根据配置的主题中的colorPrimaryDark设置状态栏颜色,
 * 控制状态栏颜色需要修改statusBarColor返回值
 * 根据colorPrimary设置导航栏颜色,控制导航栏颜色需要修改navigationBarColor返回值 如果需要设置为透明状态栏,重写translucentStatusBar修改返回值
 */
public class SystemUIConfig {

    private Activity activity;

    public SystemUIConfig(Activity activity) {
        this.activity = activity;
    }

    public void setDefaultSystemUI() {
        Window window = this.activity.getWindow();
        // TBD
    }

    /**
     * 设置StatusBar 穿透
     */
    public void setTranslate() {
        Window window = this.activity.getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
    }

    /**
     * 设置沉浸式
     *
     * @param statusBarColor     statusBar 颜色
     * @param navigationBarColor navigation bar 颜色
     */
    public void setStatusBarColor(int statusBarColor, int navigationBarColor) {
        Window window = this.activity.getWindow();
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        if (statusBarColor != 0) {//状态栏
            window.setStatusBarColor(statusBarColor);
        }
        if (navigationBarColor != 0) { //虚拟按键(导航栏)背景
            window.setNavigationBarColor(navigationBarColor);
        }
    }

    public void setStatusBarIconBlack(){
        Window window = this.activity.getWindow();
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    }

}
